import pymongo
from common import download as log

LOG = log.get_logger()

CONNECTION_STR = 'mongodb://192.168.0.196:27017/?readPreference=primary&appname=MongoDB%20Compass%20Community&ssl=false'
DATA_BASE_OLD = 'javbook_new'  # 旧数据库名
DATA_BASE_NEW = 'movies_record'  # 新数据库名
DB_COL_OLD = 'others'  # 旧表名
DB_COL_NEW = 'javbook'  # 新表名

'''
移动数据库数据：javbook_new->movies_record
'''
def move_data():
    # 连接数据库
    db_client = pymongo.MongoClient(CONNECTION_STR)
    db_database_old = db_client[DATA_BASE_OLD]
    db_col_old = db_database_old[DB_COL_OLD]
    db_database_new = db_client[DATA_BASE_NEW]
    db_col_new = db_database_new[DB_COL_NEW]

    # 查询
    all_data = list(db_col_old.find())
    for a in all_data:
        num = a['num']
        series = a['series']
        year = a['year']
        detail_url = a['detail_url']
        tor = ''
        tor_name = ''
        is_download = 'N'
        is_keep = 'N'

        dic = {'num': num, 'series': series, 'year': year, 'detail_url': detail_url, 'tor': tor, 'tor_name': tor_name,
               'is_download': is_download, 'is_keep': is_keep}
        print(dic)
        db_col_new.insert_one(dic)

    print('插入了{}个'.format(len(all_data)))
    db_client.close()


move_data()
